package com.zhongke.cotrun.common.payUtil;


import java.util.Iterator;
import java.util.Set;
import java.util.SortedMap;
import java.util.Map;

public class Sign {
	
	 public static String createSign(String characterEncoding,SortedMap<Object,Object> parameters,String key){
         StringBuffer sb = new StringBuffer();
         Set es = parameters.entrySet();
         Iterator it = es.iterator();
         while(it.hasNext()) {
             Map.Entry entry = (Map.Entry)it.next();
             String k = (String)entry.getKey();
             Object v = entry.getValue();
             if(null != v && !"".equals(v) 
                     && !"sign".equals(k) && !"key".equals(k)) {
                 sb.append(k + "=" + v + "&");
             }
         }
         sb.append("key=" +key);
        //System.out.println("====sb==========="+sb);
         String sign = MD5Util.MD5Encode(sb.toString(), characterEncoding).toUpperCase();
         return sign;
     }
 
   /*public static void main(String[] args) {
	   SortedMap<Object,Object> jsapimay = new TreeMap<Object,Object>();
		jsapimay.put("jsapi_ticket","kgt8ON7yVITDhtdwci0qeQ6-3IISHUbAvd6yoFGdQTVDODvGkFtxuhCMK70dCwnMtlcNfwFAMoSUBQGQyuYnJA");
		jsapimay.put("noncestr", "K7XfVMeqIcYTXoWh");//随时字符串
		jsapimay.put("timestamp","1462511888596");//时间戳
		jsapimay.put("url","http://localhost/IshareAction.do");
        String sign = Sign.createShareSign(jsapimay);
        System.out.println("========="+sign);
    };*/
}